﻿#include "Test.service.h"
#include "XyNet/Common/Cast.h"
#include "XyNet/Common/Exception.h"

using namespace XyNet;

namespace XyNetTest
{

ServerUserService::LoginMethod::Controller::Controller(RpcSocketChannel* socketChannel)
	: RpcController(socketChannel) {}

shared_ptr<RpcError> ServerUserService::LoginMethod::Controller::createError(int code) const
{
	switch (code)
	{
	case (int)0x922FEB8C:
		return std::make_shared<RpcError>(0x922FEB8C, "AlreadyLogin", "已经是登陆状态");
	default:
		return RpcController::createError(code);
	}
}

ServerUserService::LoginMethod::Argument::Argument()
	: RpcArgument(std::make_shared<Request>(), std::make_shared<Response>()) {}

shared_ptr<ServerUserService::LoginMethod::Controller> ServerUserService::LoginMethod::Argument::getController()
{
	return XYNET_POINTER_DOWNCAST<Controller>(_controller);
}

shared_ptr<const ServerUserService::LoginMethod::Request> ServerUserService::LoginMethod::Argument::getRequest() const
{
	return XYNET_POINTER_DOWNCAST<Request>(_request);
}

shared_ptr<ServerUserService::LoginMethod::Response> ServerUserService::LoginMethod::Argument::getResponse()
{
	return XYNET_POINTER_DOWNCAST<Response>(_response);
}

shared_ptr<RpcArgument> ServerUserService::LoginMethod::Argument::clone()
{
	XYNET_CHECK(!_controller);
	auto copy = std::make_shared<Argument>();
	copy->_request->CopyFrom(*_request);
	copy->_response->CopyFrom(*_response);
	return copy;
}

void ServerUserService::LoginMethod::Argument::initializeController(RpcSocketChannel* socketChannel)
{
	XYNET_CHECK(!_controller);
	_controller = std::make_shared<Controller>(socketChannel);
}

ServerUserService::LoginMethod::Callback::Callback(
	shared_ptr<RpcArgument> argument,
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
	: RpcCallback(argument)
	, _responseHandler(responseHandler), _exceptionHandler(exceptionHandler) {}

shared_ptr<RpcCallback> ServerUserService::LoginMethod::Callback::clone()
{
	return std::make_shared<Callback>(_argument->clone(), _responseHandler, _exceptionHandler);
}

void ServerUserService::LoginMethod::Callback::doResponseHandler()
{
	if (_responseHandler)
		_responseHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
}

void ServerUserService::LoginMethod::Callback::doExceptionHandler()
{
	if (_exceptionHandler)
		_exceptionHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
	else
		XYNET_HANDLE_EXCEPTION(Exception(_argument->getController()->getError()->getInfo()));
}

ServerUserService::LoginMethod::LoginMethod(shared_ptr<RpcChannel> channel)
	: RpcMethod("Login", 0x14E4C96B, 0x0282FAAB), _channel(channel), _argument(std::make_shared<Argument>()) {}

shared_ptr<ServerUserService::LoginMethod::Request> ServerUserService::LoginMethod::getRequest()
{
	return const_pointer_cast<Request>(
		XYNET_POINTER_DOWNCAST<Argument>(_argument)->getRequest());
}

void ServerUserService::LoginMethod::call(
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
{
	_channel->callMethod(this, std::make_shared<Callback>(_argument, responseHandler, exceptionHandler));
}

ServerUserService::LogoutMethod::Controller::Controller(RpcSocketChannel* socketChannel)
	: RpcController(socketChannel) {}

shared_ptr<RpcError> ServerUserService::LogoutMethod::Controller::createError(int code) const
{
	switch (code)
	{
	case (int)0xC7F45C36:
		return std::make_shared<RpcError>(0xC7F45C36, "AlreadyLogout", "已经是登出状态");
	default:
		return RpcController::createError(code);
	}
}

ServerUserService::LogoutMethod::Argument::Argument()
	: RpcArgument(std::make_shared<Request>(), std::make_shared<Response>()) {}

shared_ptr<ServerUserService::LogoutMethod::Controller> ServerUserService::LogoutMethod::Argument::getController()
{
	return XYNET_POINTER_DOWNCAST<Controller>(_controller);
}

shared_ptr<const ServerUserService::LogoutMethod::Request> ServerUserService::LogoutMethod::Argument::getRequest() const
{
	return XYNET_POINTER_DOWNCAST<Request>(_request);
}

shared_ptr<ServerUserService::LogoutMethod::Response> ServerUserService::LogoutMethod::Argument::getResponse()
{
	return XYNET_POINTER_DOWNCAST<Response>(_response);
}

shared_ptr<RpcArgument> ServerUserService::LogoutMethod::Argument::clone()
{
	XYNET_CHECK(!_controller);
	auto copy = std::make_shared<Argument>();
	copy->_request->CopyFrom(*_request);
	copy->_response->CopyFrom(*_response);
	return copy;
}

void ServerUserService::LogoutMethod::Argument::initializeController(RpcSocketChannel* socketChannel)
{
	XYNET_CHECK(!_controller);
	_controller = std::make_shared<Controller>(socketChannel);
}

ServerUserService::LogoutMethod::Callback::Callback(
	shared_ptr<RpcArgument> argument,
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
	: RpcCallback(argument)
	, _responseHandler(responseHandler), _exceptionHandler(exceptionHandler) {}

shared_ptr<RpcCallback> ServerUserService::LogoutMethod::Callback::clone()
{
	return std::make_shared<Callback>(_argument->clone(), _responseHandler, _exceptionHandler);
}

void ServerUserService::LogoutMethod::Callback::doResponseHandler()
{
	if (_responseHandler)
		_responseHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
}

void ServerUserService::LogoutMethod::Callback::doExceptionHandler()
{
	if (_exceptionHandler)
		_exceptionHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
	else
		XYNET_HANDLE_EXCEPTION(Exception(_argument->getController()->getError()->getInfo()));
}

ServerUserService::LogoutMethod::LogoutMethod(shared_ptr<RpcChannel> channel)
	: RpcMethod("Logout", 0x19F06032, 0x0282FAAB), _channel(channel), _argument(std::make_shared<Argument>()) {}

shared_ptr<ServerUserService::LogoutMethod::Request> ServerUserService::LogoutMethod::getRequest()
{
	return const_pointer_cast<Request>(
		XYNET_POINTER_DOWNCAST<Argument>(_argument)->getRequest());
}

void ServerUserService::LogoutMethod::call(
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
{
	_channel->callMethod(this, std::make_shared<Callback>(_argument, responseHandler, exceptionHandler));
}

ServerUserService::ServerUserService() : RpcService("ServerUserService", 0x0282FAAB) {}

shared_ptr<RpcArgument> ServerUserService::createMethodArgument(int methodId) const
{
	switch (methodId)
	{
	case (int)0x14E4C96B:
		return std::make_shared<LoginMethod::Argument>();
	case (int)0x19F06032:
		return std::make_shared<LogoutMethod::Argument>();
	default:
		XYNET_CHECK(false);
		return nullptr;
	}
}

void ServerUserService::onMethod(int methodId, RpcArgument* argument)
{
	switch (methodId)
	{
	case (int)0x14E4C96B:
		onLogin(XYNET_DOWNCAST<LoginMethod::Argument*>(argument));
		break;
	case (int)0x19F06032:
		onLogout(XYNET_DOWNCAST<LogoutMethod::Argument*>(argument));
		break;
	default:
		XYNET_CHECK(false);
	}
}

ClientUserService::ElsewhereLoginMethod::Argument::Argument()
	: RpcArgument(std::make_shared<Request>(), std::make_shared<Response>()) {}

shared_ptr<ClientUserService::ElsewhereLoginMethod::Controller> ClientUserService::ElsewhereLoginMethod::Argument::getController()
{
	return XYNET_POINTER_DOWNCAST<Controller>(_controller);
}

shared_ptr<const ClientUserService::ElsewhereLoginMethod::Request> ClientUserService::ElsewhereLoginMethod::Argument::getRequest() const
{
	return XYNET_POINTER_DOWNCAST<Request>(_request);
}

shared_ptr<ClientUserService::ElsewhereLoginMethod::Response> ClientUserService::ElsewhereLoginMethod::Argument::getResponse()
{
	return XYNET_POINTER_DOWNCAST<Response>(_response);
}

shared_ptr<RpcArgument> ClientUserService::ElsewhereLoginMethod::Argument::clone()
{
	XYNET_CHECK(!_controller);
	auto copy = std::make_shared<Argument>();
	copy->_request->CopyFrom(*_request);
	copy->_response->CopyFrom(*_response);
	return copy;
}

void ClientUserService::ElsewhereLoginMethod::Argument::initializeController(RpcSocketChannel* socketChannel)
{
	XYNET_CHECK(!_controller);
	_controller = std::make_shared<Controller>(socketChannel);
}

ClientUserService::ElsewhereLoginMethod::Callback::Callback(
	shared_ptr<RpcArgument> argument,
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
	: RpcCallback(argument)
	, _responseHandler(responseHandler), _exceptionHandler(exceptionHandler) {}

shared_ptr<RpcCallback> ClientUserService::ElsewhereLoginMethod::Callback::clone()
{
	return std::make_shared<Callback>(_argument->clone(), _responseHandler, _exceptionHandler);
}

void ClientUserService::ElsewhereLoginMethod::Callback::doResponseHandler()
{
	if (_responseHandler)
		_responseHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
}

void ClientUserService::ElsewhereLoginMethod::Callback::doExceptionHandler()
{
	if (_exceptionHandler)
		_exceptionHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
	else
		XYNET_HANDLE_EXCEPTION(Exception(_argument->getController()->getError()->getInfo()));
}

ClientUserService::ElsewhereLoginMethod::ElsewhereLoginMethod(shared_ptr<RpcChannel> channel)
	: RpcMethod("ElsewhereLogin", 0xE0B5BF17, 0xE42F61E9), _channel(channel), _argument(std::make_shared<Argument>()) {}

shared_ptr<ClientUserService::ElsewhereLoginMethod::Request> ClientUserService::ElsewhereLoginMethod::getRequest()
{
	return const_pointer_cast<Request>(
		XYNET_POINTER_DOWNCAST<Argument>(_argument)->getRequest());
}

void ClientUserService::ElsewhereLoginMethod::call(
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
{
	_channel->callMethod(this, std::make_shared<Callback>(_argument, responseHandler, exceptionHandler));
}

ClientUserService::OtherLoginMethod::Argument::Argument()
	: RpcArgument(std::make_shared<Request>(), std::make_shared<Response>()) {}

shared_ptr<ClientUserService::OtherLoginMethod::Controller> ClientUserService::OtherLoginMethod::Argument::getController()
{
	return XYNET_POINTER_DOWNCAST<Controller>(_controller);
}

shared_ptr<const ClientUserService::OtherLoginMethod::Request> ClientUserService::OtherLoginMethod::Argument::getRequest() const
{
	return XYNET_POINTER_DOWNCAST<Request>(_request);
}

shared_ptr<ClientUserService::OtherLoginMethod::Response> ClientUserService::OtherLoginMethod::Argument::getResponse()
{
	return XYNET_POINTER_DOWNCAST<Response>(_response);
}

shared_ptr<RpcArgument> ClientUserService::OtherLoginMethod::Argument::clone()
{
	XYNET_CHECK(!_controller);
	auto copy = std::make_shared<Argument>();
	copy->_request->CopyFrom(*_request);
	copy->_response->CopyFrom(*_response);
	return copy;
}

void ClientUserService::OtherLoginMethod::Argument::initializeController(RpcSocketChannel* socketChannel)
{
	XYNET_CHECK(!_controller);
	_controller = std::make_shared<Controller>(socketChannel);
}

ClientUserService::OtherLoginMethod::Callback::Callback(
	shared_ptr<RpcArgument> argument,
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
	: RpcCallback(argument)
	, _responseHandler(responseHandler), _exceptionHandler(exceptionHandler) {}

shared_ptr<RpcCallback> ClientUserService::OtherLoginMethod::Callback::clone()
{
	return std::make_shared<Callback>(_argument->clone(), _responseHandler, _exceptionHandler);
}

void ClientUserService::OtherLoginMethod::Callback::doResponseHandler()
{
	if (_responseHandler)
		_responseHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
}

void ClientUserService::OtherLoginMethod::Callback::doExceptionHandler()
{
	if (_exceptionHandler)
		_exceptionHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
	else
		XYNET_HANDLE_EXCEPTION(Exception(_argument->getController()->getError()->getInfo()));
}

ClientUserService::OtherLoginMethod::OtherLoginMethod(shared_ptr<RpcChannel> channel)
	: RpcMethod("OtherLogin", 0x0DC1F510, 0xE42F61E9), _channel(channel), _argument(std::make_shared<Argument>()) {}

shared_ptr<ClientUserService::OtherLoginMethod::Request> ClientUserService::OtherLoginMethod::getRequest()
{
	return const_pointer_cast<Request>(
		XYNET_POINTER_DOWNCAST<Argument>(_argument)->getRequest());
}

void ClientUserService::OtherLoginMethod::call(
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
{
	_channel->callMethod(this, std::make_shared<Callback>(_argument, responseHandler, exceptionHandler));
}

ClientUserService::OtherLogoutMethod::Argument::Argument()
	: RpcArgument(std::make_shared<Request>(), std::make_shared<Response>()) {}

shared_ptr<ClientUserService::OtherLogoutMethod::Controller> ClientUserService::OtherLogoutMethod::Argument::getController()
{
	return XYNET_POINTER_DOWNCAST<Controller>(_controller);
}

shared_ptr<const ClientUserService::OtherLogoutMethod::Request> ClientUserService::OtherLogoutMethod::Argument::getRequest() const
{
	return XYNET_POINTER_DOWNCAST<Request>(_request);
}

shared_ptr<ClientUserService::OtherLogoutMethod::Response> ClientUserService::OtherLogoutMethod::Argument::getResponse()
{
	return XYNET_POINTER_DOWNCAST<Response>(_response);
}

shared_ptr<RpcArgument> ClientUserService::OtherLogoutMethod::Argument::clone()
{
	XYNET_CHECK(!_controller);
	auto copy = std::make_shared<Argument>();
	copy->_request->CopyFrom(*_request);
	copy->_response->CopyFrom(*_response);
	return copy;
}

void ClientUserService::OtherLogoutMethod::Argument::initializeController(RpcSocketChannel* socketChannel)
{
	XYNET_CHECK(!_controller);
	_controller = std::make_shared<Controller>(socketChannel);
}

ClientUserService::OtherLogoutMethod::Callback::Callback(
	shared_ptr<RpcArgument> argument,
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
	: RpcCallback(argument)
	, _responseHandler(responseHandler), _exceptionHandler(exceptionHandler) {}

shared_ptr<RpcCallback> ClientUserService::OtherLogoutMethod::Callback::clone()
{
	return std::make_shared<Callback>(_argument->clone(), _responseHandler, _exceptionHandler);
}

void ClientUserService::OtherLogoutMethod::Callback::doResponseHandler()
{
	if (_responseHandler)
		_responseHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
}

void ClientUserService::OtherLogoutMethod::Callback::doExceptionHandler()
{
	if (_exceptionHandler)
		_exceptionHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
	else
		XYNET_HANDLE_EXCEPTION(Exception(_argument->getController()->getError()->getInfo()));
}

ClientUserService::OtherLogoutMethod::OtherLogoutMethod(shared_ptr<RpcChannel> channel)
	: RpcMethod("OtherLogout", 0xFC647056, 0xE42F61E9), _channel(channel), _argument(std::make_shared<Argument>()) {}

shared_ptr<ClientUserService::OtherLogoutMethod::Request> ClientUserService::OtherLogoutMethod::getRequest()
{
	return const_pointer_cast<Request>(
		XYNET_POINTER_DOWNCAST<Argument>(_argument)->getRequest());
}

void ClientUserService::OtherLogoutMethod::call(
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
{
	_channel->callMethod(this, std::make_shared<Callback>(_argument, responseHandler, exceptionHandler));
}

ClientUserService::ClientUserService() : RpcService("ClientUserService", 0xE42F61E9) {}

shared_ptr<RpcArgument> ClientUserService::createMethodArgument(int methodId) const
{
	switch (methodId)
	{
	case (int)0xE0B5BF17:
		return std::make_shared<ElsewhereLoginMethod::Argument>();
	case (int)0x0DC1F510:
		return std::make_shared<OtherLoginMethod::Argument>();
	case (int)0xFC647056:
		return std::make_shared<OtherLogoutMethod::Argument>();
	default:
		XYNET_CHECK(false);
		return nullptr;
	}
}

void ClientUserService::onMethod(int methodId, RpcArgument* argument)
{
	switch (methodId)
	{
	case (int)0xE0B5BF17:
		onElsewhereLogin(XYNET_DOWNCAST<ElsewhereLoginMethod::Argument*>(argument));
		break;
	case (int)0x0DC1F510:
		onOtherLogin(XYNET_DOWNCAST<OtherLoginMethod::Argument*>(argument));
		break;
	case (int)0xFC647056:
		onOtherLogout(XYNET_DOWNCAST<OtherLogoutMethod::Argument*>(argument));
		break;
	default:
		XYNET_CHECK(false);
	}
}

ServerChatService::PublicSayMethod::Argument::Argument()
	: RpcArgument(std::make_shared<Request>(), std::make_shared<Response>()) {}

shared_ptr<ServerChatService::PublicSayMethod::Controller> ServerChatService::PublicSayMethod::Argument::getController()
{
	return XYNET_POINTER_DOWNCAST<Controller>(_controller);
}

shared_ptr<const ServerChatService::PublicSayMethod::Request> ServerChatService::PublicSayMethod::Argument::getRequest() const
{
	return XYNET_POINTER_DOWNCAST<Request>(_request);
}

shared_ptr<ServerChatService::PublicSayMethod::Response> ServerChatService::PublicSayMethod::Argument::getResponse()
{
	return XYNET_POINTER_DOWNCAST<Response>(_response);
}

shared_ptr<RpcArgument> ServerChatService::PublicSayMethod::Argument::clone()
{
	XYNET_CHECK(!_controller);
	auto copy = std::make_shared<Argument>();
	copy->_request->CopyFrom(*_request);
	copy->_response->CopyFrom(*_response);
	return copy;
}

void ServerChatService::PublicSayMethod::Argument::initializeController(RpcSocketChannel* socketChannel)
{
	XYNET_CHECK(!_controller);
	_controller = std::make_shared<Controller>(socketChannel);
}

ServerChatService::PublicSayMethod::Callback::Callback(
	shared_ptr<RpcArgument> argument,
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
	: RpcCallback(argument)
	, _responseHandler(responseHandler), _exceptionHandler(exceptionHandler) {}

shared_ptr<RpcCallback> ServerChatService::PublicSayMethod::Callback::clone()
{
	return std::make_shared<Callback>(_argument->clone(), _responseHandler, _exceptionHandler);
}

void ServerChatService::PublicSayMethod::Callback::doResponseHandler()
{
	if (_responseHandler)
		_responseHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
}

void ServerChatService::PublicSayMethod::Callback::doExceptionHandler()
{
	if (_exceptionHandler)
		_exceptionHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
	else
		XYNET_HANDLE_EXCEPTION(Exception(_argument->getController()->getError()->getInfo()));
}

ServerChatService::PublicSayMethod::PublicSayMethod(shared_ptr<RpcChannel> channel)
	: RpcMethod("PublicSay", 0x87168095, 0x1EAE74A9), _channel(channel), _argument(std::make_shared<Argument>()) {}

shared_ptr<ServerChatService::PublicSayMethod::Request> ServerChatService::PublicSayMethod::getRequest()
{
	return const_pointer_cast<Request>(
		XYNET_POINTER_DOWNCAST<Argument>(_argument)->getRequest());
}

void ServerChatService::PublicSayMethod::call(
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
{
	_channel->callMethod(this, std::make_shared<Callback>(_argument, responseHandler, exceptionHandler));
}

ServerChatService::PrivateSayMethod::Controller::Controller(RpcSocketChannel* socketChannel)
	: RpcController(socketChannel) {}

shared_ptr<RpcError> ServerChatService::PrivateSayMethod::Controller::createError(int code) const
{
	switch (code)
	{
	case (int)0x2F0E26A9:
		return std::make_shared<RpcError>(0x2F0E26A9, "TargetUserNotLogin", "目标用户未登陆");
	default:
		return RpcController::createError(code);
	}
}

ServerChatService::PrivateSayMethod::Argument::Argument()
	: RpcArgument(std::make_shared<Request>(), std::make_shared<Response>()) {}

shared_ptr<ServerChatService::PrivateSayMethod::Controller> ServerChatService::PrivateSayMethod::Argument::getController()
{
	return XYNET_POINTER_DOWNCAST<Controller>(_controller);
}

shared_ptr<const ServerChatService::PrivateSayMethod::Request> ServerChatService::PrivateSayMethod::Argument::getRequest() const
{
	return XYNET_POINTER_DOWNCAST<Request>(_request);
}

shared_ptr<ServerChatService::PrivateSayMethod::Response> ServerChatService::PrivateSayMethod::Argument::getResponse()
{
	return XYNET_POINTER_DOWNCAST<Response>(_response);
}

shared_ptr<RpcArgument> ServerChatService::PrivateSayMethod::Argument::clone()
{
	XYNET_CHECK(!_controller);
	auto copy = std::make_shared<Argument>();
	copy->_request->CopyFrom(*_request);
	copy->_response->CopyFrom(*_response);
	return copy;
}

void ServerChatService::PrivateSayMethod::Argument::initializeController(RpcSocketChannel* socketChannel)
{
	XYNET_CHECK(!_controller);
	_controller = std::make_shared<Controller>(socketChannel);
}

ServerChatService::PrivateSayMethod::Callback::Callback(
	shared_ptr<RpcArgument> argument,
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
	: RpcCallback(argument)
	, _responseHandler(responseHandler), _exceptionHandler(exceptionHandler) {}

shared_ptr<RpcCallback> ServerChatService::PrivateSayMethod::Callback::clone()
{
	return std::make_shared<Callback>(_argument->clone(), _responseHandler, _exceptionHandler);
}

void ServerChatService::PrivateSayMethod::Callback::doResponseHandler()
{
	if (_responseHandler)
		_responseHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
}

void ServerChatService::PrivateSayMethod::Callback::doExceptionHandler()
{
	if (_exceptionHandler)
		_exceptionHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
	else
		XYNET_HANDLE_EXCEPTION(Exception(_argument->getController()->getError()->getInfo()));
}

ServerChatService::PrivateSayMethod::PrivateSayMethod(shared_ptr<RpcChannel> channel)
	: RpcMethod("PrivateSay", 0xBAC5103C, 0x1EAE74A9), _channel(channel), _argument(std::make_shared<Argument>()) {}

shared_ptr<ServerChatService::PrivateSayMethod::Request> ServerChatService::PrivateSayMethod::getRequest()
{
	return const_pointer_cast<Request>(
		XYNET_POINTER_DOWNCAST<Argument>(_argument)->getRequest());
}

void ServerChatService::PrivateSayMethod::call(
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
{
	_channel->callMethod(this, std::make_shared<Callback>(_argument, responseHandler, exceptionHandler));
}

ServerChatService::ServerChatService() : RpcService("ServerChatService", 0x1EAE74A9) {}

shared_ptr<RpcArgument> ServerChatService::createMethodArgument(int methodId) const
{
	switch (methodId)
	{
	case (int)0x87168095:
		return std::make_shared<PublicSayMethod::Argument>();
	case (int)0xBAC5103C:
		return std::make_shared<PrivateSayMethod::Argument>();
	default:
		XYNET_CHECK(false);
		return nullptr;
	}
}

void ServerChatService::onMethod(int methodId, RpcArgument* argument)
{
	switch (methodId)
	{
	case (int)0x87168095:
		onPublicSay(XYNET_DOWNCAST<PublicSayMethod::Argument*>(argument));
		break;
	case (int)0xBAC5103C:
		onPrivateSay(XYNET_DOWNCAST<PrivateSayMethod::Argument*>(argument));
		break;
	default:
		XYNET_CHECK(false);
	}
}

ClientChatService::PushMessageMethod::Argument::Argument()
	: RpcArgument(std::make_shared<Request>(), std::make_shared<Response>()) {}

shared_ptr<ClientChatService::PushMessageMethod::Controller> ClientChatService::PushMessageMethod::Argument::getController()
{
	return XYNET_POINTER_DOWNCAST<Controller>(_controller);
}

shared_ptr<const ClientChatService::PushMessageMethod::Request> ClientChatService::PushMessageMethod::Argument::getRequest() const
{
	return XYNET_POINTER_DOWNCAST<Request>(_request);
}

shared_ptr<ClientChatService::PushMessageMethod::Response> ClientChatService::PushMessageMethod::Argument::getResponse()
{
	return XYNET_POINTER_DOWNCAST<Response>(_response);
}

shared_ptr<RpcArgument> ClientChatService::PushMessageMethod::Argument::clone()
{
	XYNET_CHECK(!_controller);
	auto copy = std::make_shared<Argument>();
	copy->_request->CopyFrom(*_request);
	copy->_response->CopyFrom(*_response);
	return copy;
}

void ClientChatService::PushMessageMethod::Argument::initializeController(RpcSocketChannel* socketChannel)
{
	XYNET_CHECK(!_controller);
	_controller = std::make_shared<Controller>(socketChannel);
}

ClientChatService::PushMessageMethod::Callback::Callback(
	shared_ptr<RpcArgument> argument,
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
	: RpcCallback(argument)
	, _responseHandler(responseHandler), _exceptionHandler(exceptionHandler) {}

shared_ptr<RpcCallback> ClientChatService::PushMessageMethod::Callback::clone()
{
	return std::make_shared<Callback>(_argument->clone(), _responseHandler, _exceptionHandler);
}

void ClientChatService::PushMessageMethod::Callback::doResponseHandler()
{
	if (_responseHandler)
		_responseHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
}

void ClientChatService::PushMessageMethod::Callback::doExceptionHandler()
{
	if (_exceptionHandler)
		_exceptionHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
	else
		XYNET_HANDLE_EXCEPTION(Exception(_argument->getController()->getError()->getInfo()));
}

ClientChatService::PushMessageMethod::PushMessageMethod(shared_ptr<RpcChannel> channel)
	: RpcMethod("PushMessage", 0x97B0152D, 0xF803EFEB), _channel(channel), _argument(std::make_shared<Argument>()) {}

shared_ptr<ClientChatService::PushMessageMethod::Request> ClientChatService::PushMessageMethod::getRequest()
{
	return const_pointer_cast<Request>(
		XYNET_POINTER_DOWNCAST<Argument>(_argument)->getRequest());
}

void ClientChatService::PushMessageMethod::call(
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
{
	_channel->callMethod(this, std::make_shared<Callback>(_argument, responseHandler, exceptionHandler));
}

ClientChatService::OtherPublicSayMethod::Argument::Argument()
	: RpcArgument(std::make_shared<Request>(), std::make_shared<Response>()) {}

shared_ptr<ClientChatService::OtherPublicSayMethod::Controller> ClientChatService::OtherPublicSayMethod::Argument::getController()
{
	return XYNET_POINTER_DOWNCAST<Controller>(_controller);
}

shared_ptr<const ClientChatService::OtherPublicSayMethod::Request> ClientChatService::OtherPublicSayMethod::Argument::getRequest() const
{
	return XYNET_POINTER_DOWNCAST<Request>(_request);
}

shared_ptr<ClientChatService::OtherPublicSayMethod::Response> ClientChatService::OtherPublicSayMethod::Argument::getResponse()
{
	return XYNET_POINTER_DOWNCAST<Response>(_response);
}

shared_ptr<RpcArgument> ClientChatService::OtherPublicSayMethod::Argument::clone()
{
	XYNET_CHECK(!_controller);
	auto copy = std::make_shared<Argument>();
	copy->_request->CopyFrom(*_request);
	copy->_response->CopyFrom(*_response);
	return copy;
}

void ClientChatService::OtherPublicSayMethod::Argument::initializeController(RpcSocketChannel* socketChannel)
{
	XYNET_CHECK(!_controller);
	_controller = std::make_shared<Controller>(socketChannel);
}

ClientChatService::OtherPublicSayMethod::Callback::Callback(
	shared_ptr<RpcArgument> argument,
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
	: RpcCallback(argument)
	, _responseHandler(responseHandler), _exceptionHandler(exceptionHandler) {}

shared_ptr<RpcCallback> ClientChatService::OtherPublicSayMethod::Callback::clone()
{
	return std::make_shared<Callback>(_argument->clone(), _responseHandler, _exceptionHandler);
}

void ClientChatService::OtherPublicSayMethod::Callback::doResponseHandler()
{
	if (_responseHandler)
		_responseHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
}

void ClientChatService::OtherPublicSayMethod::Callback::doExceptionHandler()
{
	if (_exceptionHandler)
		_exceptionHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
	else
		XYNET_HANDLE_EXCEPTION(Exception(_argument->getController()->getError()->getInfo()));
}

ClientChatService::OtherPublicSayMethod::OtherPublicSayMethod(shared_ptr<RpcChannel> channel)
	: RpcMethod("OtherPublicSay", 0xD25B3332, 0xF803EFEB), _channel(channel), _argument(std::make_shared<Argument>()) {}

shared_ptr<ClientChatService::OtherPublicSayMethod::Request> ClientChatService::OtherPublicSayMethod::getRequest()
{
	return const_pointer_cast<Request>(
		XYNET_POINTER_DOWNCAST<Argument>(_argument)->getRequest());
}

void ClientChatService::OtherPublicSayMethod::call(
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
{
	_channel->callMethod(this, std::make_shared<Callback>(_argument, responseHandler, exceptionHandler));
}

ClientChatService::OtherPrivateSayMethod::Argument::Argument()
	: RpcArgument(std::make_shared<Request>(), std::make_shared<Response>()) {}

shared_ptr<ClientChatService::OtherPrivateSayMethod::Controller> ClientChatService::OtherPrivateSayMethod::Argument::getController()
{
	return XYNET_POINTER_DOWNCAST<Controller>(_controller);
}

shared_ptr<const ClientChatService::OtherPrivateSayMethod::Request> ClientChatService::OtherPrivateSayMethod::Argument::getRequest() const
{
	return XYNET_POINTER_DOWNCAST<Request>(_request);
}

shared_ptr<ClientChatService::OtherPrivateSayMethod::Response> ClientChatService::OtherPrivateSayMethod::Argument::getResponse()
{
	return XYNET_POINTER_DOWNCAST<Response>(_response);
}

shared_ptr<RpcArgument> ClientChatService::OtherPrivateSayMethod::Argument::clone()
{
	XYNET_CHECK(!_controller);
	auto copy = std::make_shared<Argument>();
	copy->_request->CopyFrom(*_request);
	copy->_response->CopyFrom(*_response);
	return copy;
}

void ClientChatService::OtherPrivateSayMethod::Argument::initializeController(RpcSocketChannel* socketChannel)
{
	XYNET_CHECK(!_controller);
	_controller = std::make_shared<Controller>(socketChannel);
}

ClientChatService::OtherPrivateSayMethod::Callback::Callback(
	shared_ptr<RpcArgument> argument,
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
	: RpcCallback(argument)
	, _responseHandler(responseHandler), _exceptionHandler(exceptionHandler) {}

shared_ptr<RpcCallback> ClientChatService::OtherPrivateSayMethod::Callback::clone()
{
	return std::make_shared<Callback>(_argument->clone(), _responseHandler, _exceptionHandler);
}

void ClientChatService::OtherPrivateSayMethod::Callback::doResponseHandler()
{
	if (_responseHandler)
		_responseHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
}

void ClientChatService::OtherPrivateSayMethod::Callback::doExceptionHandler()
{
	if (_exceptionHandler)
		_exceptionHandler(XYNET_DOWNCAST<Argument*>(_argument.get()));
	else
		XYNET_HANDLE_EXCEPTION(Exception(_argument->getController()->getError()->getInfo()));
}

ClientChatService::OtherPrivateSayMethod::OtherPrivateSayMethod(shared_ptr<RpcChannel> channel)
	: RpcMethod("OtherPrivateSay", 0x8CD3B627, 0xF803EFEB), _channel(channel), _argument(std::make_shared<Argument>()) {}

shared_ptr<ClientChatService::OtherPrivateSayMethod::Request> ClientChatService::OtherPrivateSayMethod::getRequest()
{
	return const_pointer_cast<Request>(
		XYNET_POINTER_DOWNCAST<Argument>(_argument)->getRequest());
}

void ClientChatService::OtherPrivateSayMethod::call(
	const function<void(Argument*)>& responseHandler,
	const function<void(Argument*)>& exceptionHandler)
{
	_channel->callMethod(this, std::make_shared<Callback>(_argument, responseHandler, exceptionHandler));
}

ClientChatService::ClientChatService() : RpcService("ClientChatService", 0xF803EFEB) {}

shared_ptr<RpcArgument> ClientChatService::createMethodArgument(int methodId) const
{
	switch (methodId)
	{
	case (int)0x97B0152D:
		return std::make_shared<PushMessageMethod::Argument>();
	case (int)0xD25B3332:
		return std::make_shared<OtherPublicSayMethod::Argument>();
	case (int)0x8CD3B627:
		return std::make_shared<OtherPrivateSayMethod::Argument>();
	default:
		XYNET_CHECK(false);
		return nullptr;
	}
}

void ClientChatService::onMethod(int methodId, RpcArgument* argument)
{
	switch (methodId)
	{
	case (int)0x97B0152D:
		onPushMessage(XYNET_DOWNCAST<PushMessageMethod::Argument*>(argument));
		break;
	case (int)0xD25B3332:
		onOtherPublicSay(XYNET_DOWNCAST<OtherPublicSayMethod::Argument*>(argument));
		break;
	case (int)0x8CD3B627:
		onOtherPrivateSay(XYNET_DOWNCAST<OtherPrivateSayMethod::Argument*>(argument));
		break;
	default:
		XYNET_CHECK(false);
	}
}

}
